package com.hz.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.hz.control.ReplyControl;
import com.hz.model.Reply;
import com.hz.util.DateControl;

public class AddReply extends HttpServlet {
	private static final long serialVersionUID = 1L;

  @Override
  protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    request.setCharacterEncoding("UTF-8");
    int userId = Integer.parseInt(request.getParameter("userId"));    
    String content = request.getParameter("content");
    int targetId = Integer.parseInt(request.getParameter("targetId")+"");
    Reply r= new Reply();
    r.setContent(content);
    r.setReplyTime(DateControl.Date());
    r.setTargetId(targetId);
    r.setUid(userId);
    PrintWriter out = response.getWriter();
    if (ReplyControl.addReply(r)) {
      out.print("1");
    } else {
      out.print("0");
    }
  } 
}
